<include file="Public:header" />

<div id="home">

    <div id="header">

        <div style="height:28px; padding-top:10px; background:url(__PUBLIC__/Front/images/xy.png) 10px 8px no-repeat" class="logo"><span onclick=" history.go(-1);">&nbsp;</span></div>

        <div class="shoptitle"><span>购物车</span></div>

        <include file="Public:righttop" />

    </div>

</div>

<style type="text/css">
    /*空购物车显示样式*/
    .ctop{ height:150px; background:url('__PUBLIC__/front/images/cartgood.png') bottom center no-repeat}

</style>

<include file="Public:procat" />

<div style="padding:5px 10px;" id="main">

    <empty name="cart_list">

        <div class="ctop"></div>

        <p style="font-size:20px; text-align:center; height:40px; line-height:40px; color:#b8b8b8">购物车还是空空的</p>

        <p style="font-size:20px; text-align:center; height:24px; line-height:24px; color:#b8b8b8">现在就去选购吧</p>

        <p style=" padding-top:20px;text-align:center">

            <a style="width:80px; height:30px; line-height:30px;
               border-radius:5px; border:1px solid #b8b8b8; display:block;
               margin:0px auto; font-size:18px; text-decoration:underline"
               href="{:U('WeChat/Index/index')}">
                去购物
            </a>

        </p>

        <else /> 

        <table border="0" cellpadding="0" cellspacing="0" style="width:100%;background: #fff">

            <volist name="cart_list" id="vo" >

                <tr style="margin:5px 0">

                    <td style="width:80px; text-align:center; height:80px; padding-top:10px; overflow:hidden; border-bottom:1px solid #ededed;" valign="top">
                        <img src="{$vo.img}" title="{$vo.name}" border="0" style="width:78px; height:78px; border:1px solid #ededed; padding:1px; margin-left:5px;">
                    </td>

                    <td style="text-align:left;border-bottom:1px solid #ededed;color:#666" valign="top">
                        <p style="padding-left:10px; padding-right:36px; position:relative; line-height:20px;margin-top: 15px;">
                            {$vo.name}	
                        </p>

                        <p style=" padding-left:10px;font-size:12px;line-height:20px;" class="raturnprice raturnprice72">

                            <span>
                                <del style="color:#666">市场价:<font color="#5f5f5f">￥{$vo.original_price|default='0.00'}</font></del>&nbsp;&nbsp;

                                惊喜价:<font color="#FF0000" class="gprice{$vo.id}">￥{$vo.price}</font>

                            </span>

                        </p>

                        <div class="item" style="height:20px; line-height:20px; position:relative; padding-left:10px; padding-top:7px; font-size:15px;">
                            <a class="jian" style="cursor:pointer; display:block; float:left; width:35px; height:22px;line-height:22px;text-align:center;  border:1px solid #ccc; background:#ededed">-</a>
                            <input readonly="readonly" id="{$vo.id}" name="goods_number" value="{$vo.num}" class="inputBg" style="float:left;text-align: center; width:20px; height:22px; line-height:22px;border-bottom:1px solid #ccc; border-top:1px solid #ccc" type="text">
                            <a class="jia" style="cursor:pointer; display:block; float:left; width:35px; height:22px;line-height:22px;text-align:center;  border:1px solid #ccc; background:#ededed">+</a><b style="margin-left:3px;"></b>
                            &nbsp;&nbsp;小计:<font color="#FF0000" class="gzprice{$vo.id}">￥{$vo['price']*$vo['num']}</font>
                            <br/>

                            <span style="padding:2px 5px 2px 5px; color:#FF0000; 
                                  cursor:pointer; position:absolute; right:5px; top:0px; z-index:22;
                                  background:#fafafa; border:1px solid #ededed;border-radius:5px;" 
                                  data-href='{:U("WeChat/Cart/del", array("id"=>$vo["id"],"ajax"=>1))}'
                                  class="delcartid" id="72">删除</span>
                        </div>
                    </td>
                </tr>

            </volist>         
        </table>

        <p style="line-height:22px; color:#222; font-size:14px;text-align: center;
           font-weight:bold; padding:5px 0 5px 0;background:#F5B739; color:#fff">
            总金额: <span class='freeshoppandprice' style='font-size:16px'>{$cart_price}</span>元
        </p>



    </empty> 

    <script>

        function ajax_clear() {

            jConfirm('清空购物车?', '', function (data) {
                if (data) {
                    $.getJSON("{:U('WeChat/Cart/clear')}", function (data) {
                        console.log("ajax success:" + data.info);
                        window.location.reload();
                    });
                }
            });

        }

        function modify_goods($id, $num, $add) {
            var $url = "{:U('WeChat/Cart/modify')}";
            $url = $url + "&id=" + $id + "&gcount=" + $num;
            //alert($url);
            $.getJSON($url, function (data) {
                console.log("ajax success:" + data.info);

                $price = ($("#" + $id).parent().parent().find(".gprice" + $id).text()).substr(1);

                $("#" + $id).parent().find(".gzprice" + $id).text("￥" + ($num * $price).toFixed(2));
//改变商品数量更改商品结算价格
                $current_price = data.info.price;
                $(".freeshoppandprice").text($current_price);

                $cart_numm = $("#buy_price").text();
                if ($add === 1) {
                    $cart_numm++;
                } else if ($cart_numm >= 1) {
                    $cart_numm--;

                }
                $("#buy_price").text($cart_numm);
                //window.location.reload();
            });
        }

        $(document).ready(function () {
            $("a.jian").click(function () {
                //alert("d");
                $mInput = $(this).parent().find("input[name=goods_number]");
                gcount = $mInput.val();
                if (gcount > 1) {
                    gcount--;
                    $mInput.val(gcount);
                    $id = ($mInput.attr("id"));
                    modify_goods($id, gcount, 0);
                } else {
                    return;
                }
            });

            $("a.jia").click(function () {
                $mInput = $(this).parent().find("input[name=goods_number]");
                gcount = $mInput.val();
                gcount++;
                $mInput.val(gcount)
                $id = ($mInput.attr("id"));
                modify_goods($id, gcount, 1);

            });

            $("span.delcartid").click(function () {
                var $url = $(this).attr("data-href");

                jConfirm('确认删除此商品?', '', function (data) {
                    if (data) {
                        $.getJSON($url, function (data) {
                            console.log("ajax success:" + data.info);
                            window.location.reload();
                        });
                    }
                });
            });
        });
    </script>

</div>

<div style="height:40px; line-height:40px; margin:0 auto;text-align: center;bottom: 57px; max-width: 620px; position: fixed; text-align: center; height: 40px; width: 96%; padding-right:10px" >
    <a 
        onclick="return ajax_clear()" 
        style="width:48%; height:40px; line-height:40px; 
        background:#aaa; font-size:18px; color:#FFFFFF;border-radius: 5px; 
        text-align:center; cursor:pointer;
        float:left;">清空购物车</a>

    <a href="{:U('WeChat/Order/make')}"
       style="width:48%; height:40px; line-height:40px; background:#32a000;
       font-size:18px; color:#FFFFFF; text-align:center;border-radius: 5px;
       cursor:pointer; float:right;" >进入结算</a>   
</div>

<include file="Public:footer" />